"""
@author: 江同学呀
@file:  base_api.py
@date: 2025/3/13 0:07
@desc: 
    
"""
from typing import Optional, Dict, Union, Iterable

from elasticsearch import Elasticsearch

from espc.orm.model.base.base import _Base


class BaseApi(_Base):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._es: Optional[Elasticsearch] = None
        return

    def es(self, es: Elasticsearch) -> "BaseApi":
        """
        设置ES
        """
        self._es: Elasticsearch = es
        return self

    def _build(self) -> Dict:
        raise NotImplementedError("基类不提供该方法")

    def post(
            self, human: bool = None, filter_path: Union[str, Iterable[str]] = None,
            # flat_settings: bool = None,
            error_trace: bool = None, *args, **kwargs
    ) -> Dict:
        """
        POST请求
        :param human:
            Statistics are returned in a format suitable for humans (e.g. "exists_time": "1h" or "size": "1kb") and for
            computers (e.g. "exists_time_in_millis": 3600000 or "size_in_bytes": 1024). The human readable values can be
            turned off by adding ?human=false to the query string. This makes sense when the stats results are being
            consumed by a monitoring tool, rather than intended for human consumption. The default for the human flag is
            false.
            统计数据以适合人类的格式返回（例如“exists_time”： “1h”或“size”： “1kb”）和计算机（例如“exists_time_in_millis”： 3600000
            或 “size_in_bytes”： 1024）。可以通过将 ？human=false 添加到查询字符串来关闭人类可读值。当统计结果由监控工具使用而不是供人类
            使用时，这是有意义的。人为标志的默认值为 false。
        :param filter_path:
            All REST APIs accept a filter_path parameter that can be used to reduce the response returned by
            Elasticsearch. This parameter takes a comma separated list of filters expressed with the dot notation.
            所有 REST API 都接受 filter_path 参数，该参数可用于减少 Elasticsearch 返回的响应。此参数采用逗号分隔的过滤器列表，以点表示
            法表示
        # :param flat_settings:
        #     The flat_settings flag affects rendering of the lists of settings. When the flat_settings flag is true,
        #     settings are returned in a flat format.
        #     flat_settings 标志会影响设置列表的呈现。当 flat_settings 标志为 true 时，设置以平面格式返回
        :param error_trace:
            By default when a request returns an error Elasticsearch doesn’t include the stack trace of the error. You
            can enable that behavior by setting the error_trace url parameter to true.
            默认情况下，当请求返回错误时，Elasticsearch 不包含错误的堆栈跟踪。您可以通过将 error_trace url 参数设置为 true 来启用该行为。
        :param args:
        :param kwargs:
        :return:
        """
        raise NotImplementedError("基类不提供该方法")

    def get(self, *args, **kwargs) -> Dict:
        """
        GET请求
        :param args:
        :param kwargs:
        :return:
        """
        raise NotImplementedError("基类不提供该方法")

    def put(self, *args, **kwargs) -> Dict:
        """
        PUT请求
        :param args:
        :param kwargs:
        :return:
        """
        raise NotImplementedError("基类不提供该方法")

    def delete(self, *args, **kwargs) -> Dict:
        """
        DELETE请求
        :param args:
        :param kwargs:
        :return:
        """
        raise NotImplementedError("基类不提供该方法")

